<%-- 
    Document   : main
    Created on : 23/09/2014, 22:20:02
    Author     : leoomoreira
--%>

<%@page import="cronos.application.Application"%>
<%@page import="cronos.monitor.MonitorApplication"%>
<%@page import="cronos.metric.Metric"%>
<%@page import="java.util.List"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@include file="../header.jsp" %>
<div id="title">Monitor Form</div>
<% if (request.getAttribute("message") != null) {%>
<br/>
<div id="message"><%=request.getAttribute("message").toString()%></div>
<% } %>
<br/>
<form action="MonitorApplicationList" method="post">
    <div class="table">
        <div class="row">
            <div class="label">Application:</div>
            <div class="field">
                <select id="applicationId" name="applicationId">
                    <option value="">All applications</option>
                    <%
                    if (request.getAttribute("applicationList") != null) {
                        List<Application> applicationList = (List<Application>) request.getAttribute("applicationList");
                        for (Application a : applicationList) {%>
                        <option value="<%=a.getId()%>"<%= (request.getAttribute("applicationId") != null && Long.parseLong(request.getAttribute("applicationId").toString()) == a.getId() ? "selected=\"selected\"" : "")%>><%=a.getName()%></option>
                    <%  }
                    }
                    %>
                </select>
            </div>
        </div>
    </div>
    <div>
        <button type="submit" class="search">
            <img src="images/search.png" title="Search" />Search
        </button>
    </div>
</form>
<%
    if (request.getAttribute("monitorApplicationList") != null) {
%>
<br/>
<table class="list">
    <tr>
        <td class="caption">Application Id</td>
        <td class="caption">Application Name</td>
        <td class="caption">Metric Id</td>
        <td class="caption">Metric Name</td>
        <td class="caption">Time</td>
        <td class="caption">Value</td>
        <td class="twoopt">&nbsp;</td>
    </tr>
    <%
        List<MonitorApplication> result = (List<MonitorApplication>) request.getAttribute("monitorApplicationList");
        for (int i = 0; result != null && i < result.size(); i++) {
            MonitorApplication item = result.get(i);
    %>
    <tr class="<%=(i % 2 == 0 ? "even" : "odd")%>">
        <td><%= item.getApplication().getId()%></td>
        <td><%= item.getApplication().getName()%></td>
        <td><%= item.getMetric().getId()%></td>
        <td><%= item.getMetric().getName()%></td>
        <td><%= item.getTime()%></td>
        <td><%= item.getValue()%></td>
        <td>&nbsp;</td>
    </tr>
    <%
        }
    %>
</table>
<%
    }
%>
<%@include file="../footer.jsp" %>